package com.spark.common.core.entity.system;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.spark.common.annotation.Dict;
import com.spark.common.annotation.query.Query;
import com.spark.common.annotation.valid.Password;
import com.spark.common.constants.QueryConstants;
import com.spark.common.constants.RegexConstants;
import com.spark.common.constants.validGroup.AddGroup;
import com.spark.common.core.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import javax.validation.constraints.*;
import java.util.List;

/**
* 系统用户
*
* @author LYCHEE
* @date 2025/02/18 09:12
*/
@Data
@TableName("sys_user")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
public class SysUser extends BaseEntity {

    /**
     * 头像
     */
    private java.lang.String avatar;

    /**
     * 昵称
     */
    @Query(QueryConstants.QUERY_LIKE)
    @NotBlank(message = "昵称不能为空")
    private java.lang.String nickname;

    /**
     * 账号
     */
    @Query(QueryConstants.QUERY_LIKE)
    @NotBlank(message = "账号不能为空")
    @Size(min = 3, max = 30, message = "账号长度应在3到30之间")
    @Pattern(regexp = RegexConstants.USERNAME_REGEX, message = "只能包含字母和数字")
    private java.lang.String username;

    /**
     * 密码
     */
    @NotBlank(message = "密码不能为空", groups = {AddGroup.class})
    @Size(min = 5, max = 30, message = "密码长度应在5到30之间")
    @Password
    private java.lang.String password;

    /**
     * 邮箱
     */
    @Query(QueryConstants.QUERY_LIKE)
    @Email(message = "请输入有效的电子邮件地址")
    private java.lang.String email;

    /**
     * 手机号
     */
    @Query(QueryConstants.QUERY_LIKE)
    @Pattern(regexp = RegexConstants.PHONE_REGEX, message = "请输入有效的手机号")
    private java.lang.String phone;

    /**
     * 性别
     *  : 0男 1女 2未知
     */
    @Query
    @Dict(dictCode = "sex")
    private java.lang.Integer sex;

    /**
     * 状态
     *  : 0正常 1禁用
     */
    @Query
    @NotNull(message = "状态不能为空")
    @Dict(dictCode = "status")
    private java.lang.Integer status;

    /**
     * 备注
     */
    private java.lang.String remark;

    /**
     * 部门ID
     */
    @Query
    @Dict(dictTable = "sys_dept", dictCode = "id", dictText = "dept_name")
    private java.lang.String deptId;

    /**
     * 角色id组
     */
    @TableField(exist = false)
    private String roleIds;

    /**
     * 角色
     */
    @TableField(exist = false)
    private List<SysRole> roleList;

}
